module pimary

using LinearAlgebra
using AbstractAlgebra


const _ElecMass = 1.0
const _NeurMass = 1000.0
const _NeurCoul = 2.0
const _Vol = missing
const _Δβ = 0.1
const _hbar = 1.0
const _ThermWL = sqrt(2π*(_hbar^2)*_Δβ/_ElecMass)
const _WLElec = sqrt((_hbar^2)*_Δβ/_ElecMass)
const _WLNeur = sqrt((_hbar^2)*_Δβ*(1/_ElecMass+1/_NeurMass)/2)


"""
周期边条件
"""
function dis_to_1st(r::T, vol::Float64) where T
    dis = 0
    rpart = real(r)
    srpat = sign(rpart)
    while abs(rpart-dis) > vol/2
        dis += srpat * vol
    end
    return dis
end

map_to_1st(r::T, vol::Float64) where T = r - dis_to_1st(r, vol)

map_to_1st(r::Vector{T}, v::Vector{Float64}) where T = map_to_1st.(r, v)

function map_to_1st(r::Matrix{T}, v::Vector{Float64}) where T
    Np, Nd = size(r)
    ret = zeros(Np, Nd)
    for ip in Base.OneTo(Np)
        ret[ip, :] = map_to_1st(r[ip, :], v)
    end
    return ret
end



export map_to_1st, dis_to_1st


include("core/worldline.jl")
export WrdFb, WrdLn, beads, sign_permute!
export random_path, random_point
export move_at


include("core/exchmat.jl")
export free_kinetic, exch_free_kinetic


include("core/intract.jl")
export bare_Coulomb, Kelbg_repulse, Kelbg_repulse_pairs, Kelbg_attract, Kelbg_attract_pairs


include("core/thermeas.jl")
export exch_derv_beta, Kelbg_repulse_dbeta, Kelbg_attract_dbeta


include("bisect.jl")


include("rhopath.jl")
export spinful_rho_at, spinful_rho_path, spinful_rho_exch


end # module pimary
